package net.qingchuan.sharing.algorithm;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * 单分片键的标准分片场景
 */
public class TabStandardPreciseShardingAlgorithm implements PreciseShardingAlgorithm {

    public TabStandardPreciseShardingAlgorithm() {
    }

    @Override
    public String doSharding(Collection collection, PreciseShardingValue preciseShardingValue) {
        String resultTab = "";
        System.out.println("有效表信息：" + collection);
        System.out.println("分表键信息：" + preciseShardingValue.toString());
        Comparable value = preciseShardingValue.getValue();
        Long cid = (Long)value;
        if (cid > 564183025835835392L) {
            resultTab = "course_2";
        } else {
            resultTab = "course_1";
        }
        if (collection.contains(resultTab)) {
            return resultTab;
        } else {
            return "course_1";
        }
    }
}